<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# OPTIONS_GHC -fno-warn-name-shadowing #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP, DeriveDataTypeable #-}</span><span class="hs-cpp">

#if __GLASGOW_HASKELL__ &gt;= 701
</span><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-8"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Module      :  Control.Concurrent.STM.TQueue</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2012</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Stability   :  experimental</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- Portability :  non-portable (requires STM)</span><span>
</span><span id="line-17"></span><span class="hs-comment">--</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- A 'TQueue' is like a 'TChan', with two important differences:</span><span>
</span><span id="line-19"></span><span class="hs-comment">--</span><span>
</span><span id="line-20"></span><span class="hs-comment">--  * it has faster throughput than both 'TChan' and 'Chan' (although</span><span>
</span><span id="line-21"></span><span class="hs-comment">--    the costs are amortised, so the cost of individual operations</span><span>
</span><span id="line-22"></span><span class="hs-comment">--    can vary a lot).</span><span>
</span><span id="line-23"></span><span class="hs-comment">--</span><span>
</span><span id="line-24"></span><span class="hs-comment">--  * it does /not/ provide equivalents of the 'dupTChan' and</span><span>
</span><span id="line-25"></span><span class="hs-comment">--    'cloneTChan' operations.</span><span>
</span><span id="line-26"></span><span class="hs-comment">--</span><span>
</span><span id="line-27"></span><span class="hs-comment">-- The implementation is based on the traditional purely-functional</span><span>
</span><span id="line-28"></span><span class="hs-comment">-- queue representation that uses two lists to obtain amortised /O(1)/</span><span>
</span><span id="line-29"></span><span class="hs-comment">-- enqueue and dequeue operations.</span><span>
</span><span id="line-30"></span><span class="hs-comment">--</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- @since 2.4</span><span>
</span><span id="line-32"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Control.Concurrent.STM.TQueue</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-35"></span><span>        </span><span class="annot"><span class="hs-comment">-- * TQueue</span></span><span>
</span><span id="line-36"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier">TQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-37"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#newTQueue"><span class="hs-identifier">newTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-38"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#newTQueueIO"><span class="hs-identifier">newTQueueIO</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-39"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#readTQueue"><span class="hs-identifier">readTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-40"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#tryReadTQueue"><span class="hs-identifier">tryReadTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-41"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#flushTQueue"><span class="hs-identifier">flushTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-42"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#peekTQueue"><span class="hs-identifier">peekTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-43"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#tryPeekTQueue"><span class="hs-identifier">tryPeekTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-44"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#writeTQueue"><span class="hs-identifier">writeTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-45"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#unGetTQueue"><span class="hs-identifier">unGetTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-46"></span><span>        </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#isEmptyTQueue"><span class="hs-identifier">isEmptyTQueue</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-47"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.html#"><span class="hs-identifier">GHC.Conc</span></a></span><span>
</span><span id="line-50"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Control.Monad.html#"><span class="hs-identifier">Control.Monad</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier">unless</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Data.Typeable.html#"><span class="hs-identifier">Data.Typeable</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Typeable.Internal.html#Typeable"><span class="hs-identifier">Typeable</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-52"></span><span>
</span><span id="line-53"></span><span class="hs-comment">-- | 'TQueue' is an abstract type representing an unbounded FIFO channel.</span><span>
</span><span id="line-54"></span><span class="hs-comment">--</span><span>
</span><span id="line-55"></span><span class="hs-comment">-- @since 2.4</span><span>
</span><span id="line-56"></span><span class="hs-keyword">data</span><span> </span><span id="TQueue"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-var">TQueue</span></a></span></span><span> </span><span id="local-6989586621679037398"><span class="annot"><a href="#local-6989586621679037398"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="TQueue"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-var">TQueue</span></a></span></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679037398"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-57"></span><span>                       </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679037398"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-58"></span><span>  </span><span class="hs-keyword">deriving</span><span> </span><span class="annot"><a href="../../base/src/Data.Typeable.Internal.html#Typeable"><span class="hs-identifier hs-type">Typeable</span></a></span><span>
</span><span id="line-59"></span><span>
</span><span id="line-60"></span><span id="local-6989586621679037408"><span class="hs-keyword">instance</span><span> </span><span id="local-6989586621679037350"><span class="annot"><span class="hs-identifier hs-type">Eq</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037408"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-61"></span><span>  </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span id="local-6989586621679037346"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037346"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679037345"><span class="annot"><span class="annottext">== :: TQueue a -&gt; TQueue a -&gt; Bool
</span><span class="hs-operator hs-var hs-var hs-var hs-var">==</span></span></span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span id="local-6989586621679037344"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037344"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037346"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; TVar [a] -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037344"><span class="hs-identifier hs-var">b</span></a></span></span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span class="hs-comment">-- |Build and returns a new instance of 'TQueue'</span><span>
</span><span id="line-64"></span><span id="local-6989586621679037405"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#newTQueue"><span class="hs-identifier hs-type">newTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037405"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-65"></span><span id="newTQueue"><span class="annot"><span class="annottext">newTQueue :: forall a. STM (TQueue a)
</span><a href="Control.Concurrent.STM.TQueue.html#newTQueue"><span class="hs-identifier hs-var hs-var">newTQueue</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-66"></span><span>  </span><span id="local-6989586621679037339"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037339"><span class="hs-identifier hs-var">read</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; STM (TVar [a])
forall a. a -&gt; STM (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-67"></span><span>  </span><span id="local-6989586621679037337"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037337"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; STM (TVar [a])
forall a. a -&gt; STM (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVar"><span class="hs-identifier hs-var">newTVar</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-68"></span><span>  </span><span class="annot"><span class="annottext">TQueue a -&gt; STM (TQueue a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar [a] -&gt; TVar [a] -&gt; TQueue a
forall a. TVar [a] -&gt; TVar [a] -&gt; TQueue a
</span><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-var">TQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037339"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037337"><span class="hs-identifier hs-var">write</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span class="hs-comment">-- |@IO@ version of 'newTQueue'.  This is useful for creating top-level</span><span>
</span><span id="line-71"></span><span class="hs-comment">-- 'TQueue's using 'System.IO.Unsafe.unsafePerformIO', because using</span><span>
</span><span id="line-72"></span><span class="hs-comment">-- 'atomically' inside 'System.IO.Unsafe.unsafePerformIO' isn't</span><span>
</span><span id="line-73"></span><span class="hs-comment">-- possible.</span><span>
</span><span id="line-74"></span><span id="local-6989586621679037397"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#newTQueueIO"><span class="hs-identifier hs-type">newTQueueIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037397"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-75"></span><span id="newTQueueIO"><span class="annot"><span class="annottext">newTQueueIO :: forall a. IO (TQueue a)
</span><a href="Control.Concurrent.STM.TQueue.html#newTQueueIO"><span class="hs-identifier hs-var hs-var">newTQueueIO</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-76"></span><span>  </span><span id="local-6989586621679037332"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037332"><span class="hs-identifier hs-var">read</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; IO (TVar [a])
forall a. a -&gt; IO (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">newTVarIO</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-77"></span><span>  </span><span id="local-6989586621679037330"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037330"><span class="hs-identifier hs-var">write</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; IO (TVar [a])
forall a. a -&gt; IO (TVar a)
</span><a href="../../base/src/GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">newTVarIO</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-78"></span><span>  </span><span class="annot"><span class="annottext">TQueue a -&gt; IO (TQueue a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TVar [a] -&gt; TVar [a] -&gt; TQueue a
forall a. TVar [a] -&gt; TVar [a] -&gt; TQueue a
</span><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-var">TQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037332"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037330"><span class="hs-identifier hs-var">write</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-79"></span><span>
</span><span id="line-80"></span><span class="hs-comment">-- |Write a value to a 'TQueue'.</span><span>
</span><span id="line-81"></span><span id="local-6989586621679037394"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#writeTQueue"><span class="hs-identifier hs-type">writeTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037394"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679037394"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-82"></span><span id="writeTQueue"><span class="annot"><span class="annottext">writeTQueue :: forall a. TQueue a -&gt; a -&gt; STM ()
</span><a href="Control.Concurrent.STM.TQueue.html#writeTQueue"><span class="hs-identifier hs-var hs-var">writeTQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span id="local-6989586621679037328"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037328"><span class="hs-identifier hs-var">_read</span></a></span></span><span> </span><span id="local-6989586621679037327"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037327"><span class="hs-identifier hs-var">write</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679037326"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037326"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-83"></span><span>  </span><span id="local-6989586621679037325"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037325"><span class="hs-identifier hs-var">listend</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037327"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-84"></span><span>  </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037327"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037326"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037325"><span class="hs-identifier hs-var">listend</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-85"></span><span>
</span><span id="line-86"></span><span class="hs-comment">-- |Read the next value from the 'TQueue'.</span><span>
</span><span id="line-87"></span><span id="local-6989586621679037390"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#readTQueue"><span class="hs-identifier hs-type">readTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037390"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037390"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-88"></span><span id="readTQueue"><span class="annot"><span class="annottext">readTQueue :: forall a. TQueue a -&gt; STM a
</span><a href="Control.Concurrent.STM.TQueue.html#readTQueue"><span class="hs-identifier hs-var hs-var">readTQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span id="local-6989586621679037315"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037315"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679037314"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037314"><span class="hs-identifier hs-var">write</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-89"></span><span>  </span><span id="local-6989586621679037313"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037313"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037315"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-90"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037313"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-91"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679037312"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037312"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679037311"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037311"><span class="hs-identifier hs-var">xs'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-92"></span><span>      </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037315"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037311"><span class="hs-identifier hs-var">xs'</span></a></span><span>
</span><span id="line-93"></span><span>      </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037312"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-94"></span><span>    </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-95"></span><span>      </span><span id="local-6989586621679037310"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037310"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037314"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-96"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037310"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-97"></span><span>        </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM a
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-98"></span><span>        </span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-99"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679037308"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037308"><span class="hs-identifier hs-var">z</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679037307"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037307"><span class="hs-identifier hs-var">zs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037310"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-comment">-- NB. lazy: we want the transaction to be</span><span>
</span><span id="line-100"></span><span>                                  </span><span class="hs-comment">-- short, otherwise it will conflict</span><span>
</span><span id="line-101"></span><span>          </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037314"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-102"></span><span>          </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037315"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037307"><span class="hs-identifier hs-var">zs</span></a></span><span>
</span><span id="line-103"></span><span>          </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037308"><span class="hs-identifier hs-var">z</span></a></span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span class="hs-comment">-- | A version of 'readTQueue' which does not retry. Instead it</span><span>
</span><span id="line-106"></span><span class="hs-comment">-- returns @Nothing@ if no value is available.</span><span>
</span><span id="line-107"></span><span id="local-6989586621679037386"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#tryReadTQueue"><span class="hs-identifier hs-type">tryReadTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037386"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037386"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-108"></span><span id="tryReadTQueue"><span class="annot"><span class="annottext">tryReadTQueue :: forall a. TQueue a -&gt; STM (Maybe a)
</span><a href="Control.Concurrent.STM.TQueue.html#tryReadTQueue"><span class="hs-identifier hs-var hs-var">tryReadTQueue</span></a></span></span><span> </span><span id="local-6989586621679037302"><span class="annot"><span class="annottext">TQueue a
</span><a href="#local-6989586621679037302"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(a -&gt; Maybe a) -&gt; STM a -&gt; STM (Maybe a)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="../../base/src/GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="annot"><span class="annottext">a -&gt; Maybe a
forall a. a -&gt; Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TQueue a -&gt; STM a
forall a. TQueue a -&gt; STM a
</span><a href="Control.Concurrent.STM.TQueue.html#readTQueue"><span class="hs-identifier hs-var">readTQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TQueue a
</span><a href="#local-6989586621679037302"><span class="hs-identifier hs-var">c</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">STM (Maybe a) -&gt; STM (Maybe a) -&gt; STM (Maybe a)
forall a. STM a -&gt; STM a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#orElse"><span class="hs-operator hs-var">`orElse`</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-109"></span><span>
</span><span id="line-110"></span><span class="hs-comment">-- | Efficiently read the entire contents of a 'TQueue' into a list. This</span><span>
</span><span id="line-111"></span><span class="hs-comment">-- function never retries.</span><span>
</span><span id="line-112"></span><span class="hs-comment">--</span><span>
</span><span id="line-113"></span><span class="hs-comment">-- @since 2.4.5</span><span>
</span><span id="line-114"></span><span id="local-6989586621679037380"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#flushTQueue"><span class="hs-identifier hs-type">flushTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037380"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="#local-6989586621679037380"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">]</span></span><span>
</span><span id="line-115"></span><span id="flushTQueue"><span class="annot"><span class="annottext">flushTQueue :: forall a. TQueue a -&gt; STM [a]
</span><a href="Control.Concurrent.STM.TQueue.html#flushTQueue"><span class="hs-identifier hs-var hs-var">flushTQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span id="local-6989586621679037289"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037289"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679037288"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037288"><span class="hs-identifier hs-var">write</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-116"></span><span>  </span><span id="local-6989586621679037287"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037287"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037289"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-117"></span><span>  </span><span id="local-6989586621679037286"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037286"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037288"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-118"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; STM () -&gt; STM ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037287"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(STM () -&gt; STM ()) -&gt; STM () -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037289"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-119"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; STM () -&gt; STM ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="../../base/src/Control.Monad.html#unless"><span class="hs-identifier hs-var">unless</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a] -&gt; Bool
forall (t :: * -&gt; *) a. Foldable t =&gt; t a -&gt; Bool
</span><a href="../../base/src/Data.Foldable.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037286"><span class="hs-identifier hs-var">ys</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(STM () -&gt; STM ()) -&gt; STM () -&gt; STM ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037288"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-120"></span><span>  </span><span class="annot"><span class="annottext">[a] -&gt; STM [a]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037287"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a] -&gt; [a]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037286"><span class="hs-identifier hs-var">ys</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-121"></span><span>
</span><span id="line-122"></span><span class="hs-comment">-- | Get the next value from the @TQueue@ without removing it,</span><span>
</span><span id="line-123"></span><span class="hs-comment">-- retrying if the channel is empty.</span><span>
</span><span id="line-124"></span><span id="local-6989586621679037284"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#peekTQueue"><span class="hs-identifier hs-type">peekTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037284"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037284"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-125"></span><span id="peekTQueue"><span class="annot"><span class="annottext">peekTQueue :: forall a. TQueue a -&gt; STM a
</span><a href="Control.Concurrent.STM.TQueue.html#peekTQueue"><span class="hs-identifier hs-var hs-var">peekTQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span id="local-6989586621679037277"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037277"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679037276"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037276"><span class="hs-identifier hs-var">write</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-126"></span><span>  </span><span id="local-6989586621679037275"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037275"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037277"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-127"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037275"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-128"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679037274"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037274"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037274"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-129"></span><span>    </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-130"></span><span>      </span><span id="local-6989586621679037273"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037273"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037276"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-131"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037273"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-132"></span><span>        </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">STM a
forall a. STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-133"></span><span>        </span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-134"></span><span>          </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679037272"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037272"><span class="hs-identifier hs-var">z</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679037271"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037271"><span class="hs-identifier hs-var">zs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[a] -&gt; [a]
forall a. [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037273"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-comment">-- NB. lazy: we want the transaction to be</span><span>
</span><span id="line-135"></span><span>                                  </span><span class="hs-comment">-- short, otherwise it will conflict</span><span>
</span><span id="line-136"></span><span>          </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037276"><span class="hs-identifier hs-var">write</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-137"></span><span>          </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037277"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037272"><span class="hs-identifier hs-var">z</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037271"><span class="hs-identifier hs-var">zs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-138"></span><span>          </span><span class="annot"><span class="annottext">a -&gt; STM a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037272"><span class="hs-identifier hs-var">z</span></a></span><span>
</span><span id="line-139"></span><span>
</span><span id="line-140"></span><span class="hs-comment">-- | A version of 'peekTQueue' which does not retry. Instead it</span><span>
</span><span id="line-141"></span><span class="hs-comment">-- returns @Nothing@ if no value is available.</span><span>
</span><span id="line-142"></span><span id="local-6989586621679037270"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#tryPeekTQueue"><span class="hs-identifier hs-type">tryPeekTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037270"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037270"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-143"></span><span id="tryPeekTQueue"><span class="annot"><span class="annottext">tryPeekTQueue :: forall a. TQueue a -&gt; STM (Maybe a)
</span><a href="Control.Concurrent.STM.TQueue.html#tryPeekTQueue"><span class="hs-identifier hs-var hs-var">tryPeekTQueue</span></a></span></span><span> </span><span id="local-6989586621679037265"><span class="annot"><span class="annottext">TQueue a
</span><a href="#local-6989586621679037265"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-144"></span><span>  </span><span id="local-6989586621679037264"><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037264"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TQueue a -&gt; STM (Maybe a)
forall a. TQueue a -&gt; STM (Maybe a)
</span><a href="Control.Concurrent.STM.TQueue.html#tryReadTQueue"><span class="hs-identifier hs-var">tryReadTQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TQueue a
</span><a href="#local-6989586621679037265"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-145"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037264"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-146"></span><span>    </span><span class="annot"><span class="annottext">Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
forall a. Maybe a
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-147"></span><span>    </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679037263"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037263"><span class="hs-identifier hs-var">x</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-148"></span><span>      </span><span class="annot"><span class="annottext">TQueue a -&gt; a -&gt; STM ()
forall a. TQueue a -&gt; a -&gt; STM ()
</span><a href="Control.Concurrent.STM.TQueue.html#unGetTQueue"><span class="hs-identifier hs-var">unGetTQueue</span></a></span><span> </span><span class="annot"><span class="annottext">TQueue a
</span><a href="#local-6989586621679037265"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037263"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-149"></span><span>      </span><span class="annot"><span class="annottext">Maybe a -&gt; STM (Maybe a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe a
</span><a href="#local-6989586621679037264"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span class="hs-comment">-- |Put a data item back onto a channel, where it will be the next item read.</span><span>
</span><span id="line-152"></span><span id="local-6989586621679037262"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#unGetTQueue"><span class="hs-identifier hs-type">unGetTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037262"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679037262"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-153"></span><span id="unGetTQueue"><span class="annot"><span class="annottext">unGetTQueue :: forall a. TQueue a -&gt; a -&gt; STM ()
</span><a href="Control.Concurrent.STM.TQueue.html#unGetTQueue"><span class="hs-identifier hs-var hs-var">unGetTQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span id="local-6989586621679037260"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037260"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679037259"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037259"><span class="hs-identifier hs-var">_write</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679037258"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037258"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-154"></span><span>  </span><span id="local-6989586621679037257"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037257"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037260"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-155"></span><span>  </span><span class="annot"><span class="annottext">TVar [a] -&gt; [a] -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="../../base/src/GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037260"><span class="hs-identifier hs-var">read</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679037258"><span class="hs-identifier hs-var">a</span></a></span><span class="annot"><span class="annottext">a -&gt; [a] -&gt; [a]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037257"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-156"></span><span>
</span><span id="line-157"></span><span class="hs-comment">-- |Returns 'True' if the supplied 'TQueue' is empty.</span><span>
</span><span id="line-158"></span><span id="local-6989586621679037368"><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#isEmptyTQueue"><span class="hs-identifier hs-type">isEmptyTQueue</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679037368"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">STM</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span></span><span>
</span><span id="line-159"></span><span id="isEmptyTQueue"><span class="annot"><span class="annottext">isEmptyTQueue :: forall a. TQueue a -&gt; STM Bool
</span><a href="Control.Concurrent.STM.TQueue.html#isEmptyTQueue"><span class="hs-identifier hs-var hs-var">isEmptyTQueue</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Control.Concurrent.STM.TQueue.html#TQueue"><span class="hs-identifier hs-type">TQueue</span></a></span><span> </span><span id="local-6989586621679037251"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037251"><span class="hs-identifier hs-var">read</span></a></span></span><span> </span><span id="local-6989586621679037250"><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037250"><span class="hs-identifier hs-var">write</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-160"></span><span>  </span><span id="local-6989586621679037249"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037249"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037251"><span class="hs-identifier hs-var">read</span></a></span><span>
</span><span id="line-161"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037249"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-162"></span><span>    </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-163"></span><span>    </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679037248"><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037248"><span class="hs-identifier hs-var">ys</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar [a] -&gt; STM [a]
forall a. TVar a -&gt; STM a
</span><a href="../../base/src/GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar [a]
</span><a href="#local-6989586621679037250"><span class="hs-identifier hs-var">write</span></a></span><span>
</span><span id="line-164"></span><span>             </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">[a]
</span><a href="#local-6989586621679037248"><span class="hs-identifier hs-var">ys</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-165"></span><span>               </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">True</span></span><span>
</span><span id="line-166"></span><span>               </span><span class="annot"><span class="annottext">[a]
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; STM Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-167"></span></pre></body></html>